<?php
    $username='root';
	$password='';
	$database='PomocnikProjektanta';

	$baza = mysql_connect('localhost',$username,$password)
			or  die('Nieudane polaczenie: '.mysql_error());

	@mysql_select_db($database) or die("Nie odnaleziono bazy danych");

    $query = "SELECT * FROM Mapa";

    $result = mysql_query($query) or die('zapytanie niudane: '.mysql_error());
    
    echo "<table>";
    echo "<tr><td colspan=\"2\"><h4>MAPY</h4></td><tr>";
        echo "<tr><td>
                <form action=\"../akcje/przypUsMape.php?id=$id\" method=\"post\">
                    <select name=\"mapa\">";

            while($line = mysql_fetch_array($result, MYSQL_NUM))
                echo "<option VALUE=\"{$line[0]}\">{$line[1]}</option>";

        echo "</select>&nbsp;<input type=\"submit\" name=\"przypisz\" value=\"Przypisz\">
                &nbsp;|&nbsp;<input type=\"submit\" name=\"unun\" value=\"Usuń\">
                </form></td>";

        echo "<td>
                <form enctype=\"multipart/form-data\" action=\"../akcje/wstawMape.php?id=$id\" method=\"post\">
                    <input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"16000000\" />
                    <input type=\"file\" name=\"plik\" />
                    <input type=\"submit\" value=\"Dodaj\" name=\"Dodaj\" />
                </form>
        ";

    echo "</tr>
        <tr>
            <td colspan=\"2\">";
                $query = "SELECT Mapa.id_mapy, nazwa FROM Projekt_sklada_sie_z_mapy AS PM INNER JOIN Mapa WHERE PM.id_mapy=Mapa.id_mapy AND PM.id_projektu=$id";
                $wynik=mysql_query($query) or die('zapytanie niudane: '.mysql_error());
                echo "<form action=\"../akcje/wypiszMape.php?id=$id\" method=\"post\">";
                echo "<table><tr>
                    <td>Usuń</td>
                    <td>Nazwa</td>
                </tr>";
                while($line = mysql_fetch_array($wynik, MYSQL_NUM)){
                    echo "<tr><td><input type=checkbox name=\"{$line[0]}\"></td>\n";
                    echo "<td><a target=\"_blank\" href=\"../akcje/pobierzPlik.php?kat=mapa&nazwa={$line[1]}\">{$line[1]}</a></td></tr>";
                }
                echo "<tr><td><input type=submit name=\"usun\" id=\"usun\" value=\"usuń\"></td></tr></table></form>

                    </tr></table>";


?>
